export const validateRule = {

    validateDeliveryAddr:{
        validator(msg){
            return {
              validate: (rule, value, callback) => {
                console.log('!!!');
                
                if (!value) {
                  callback(new Error(msg || '请输入发货地'));
                }else{
                  callback()
                }
              },
              trigger: 'blur',
            };
        }
    },

    validateReceiveAddr:{
        validator(msg){
            return {
              validate: (rule, value, callback) => {
                if (!value) {
                    console.log('invalidate');
                  callback(new Error(msg || '请输入收货地'));
                }else{
                  callback()
                }
              },
              trigger: 'blur',
            };
        }
    },

    validateCarAmount:{
        validator(msg){
            return {
              validate: (rule, value, callback) => {
                const reg = /^[1-9]\d*$/;
                if (!value) {
                  callback(new Error(msg || '请输入车数'));
                }else if(!reg.test(value)){
                    callback(new Error(msg || '请输入大于0的数字'));
                }else{
                  callback()
                }
              },
              trigger: 'blur',
            };
        }
    },

    validateTon:{
        validator(msg){
            return {
              validate: (rule, value, callback) => {
                const reg = /^[1-9]\d*$/;
                if (!value) {
                  callback(new Error(msg || '请输入吨位'));
                }else if(!reg.test(value)){
                    callback(new Error(msg || '请输入大于0的数字'));
                }else{
                  callback()
                }
              },
              trigger: 'blur',
            };
        }
    },

    validateTotalPrice:{
        validator(msg){
            return {
              validate: (rule, value, callback) => {
                const reg = /^(([1-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g
                if (!value) {
                  callback(new Error(msg || '请输入运费合计'));
                }else if(!reg.test(value)){
                    callback(new Error(msg || '请输入大于0的数字'));
                }else{
                  callback()
                }
              },
              trigger: 'blur',
            };
        }
    },


    /**
     * 校验 IP 支持IPV4/IPV6
     * IP校验
     */
    validateIpNat: {
      validator(params) {
        return {
          validator: (rule, value, callback) => {
            // IPV4/IPV6 正则表达式
            const reg = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^::([\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:):([\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){2}:([\da-fA-F]{1,4}:){0,2}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){3}:([\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){4}:((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$/;
            if (!value) {
              callback(new Error(`请输入${params.name}`));
            } else if (!reg.test(value)) {
              callback(new Error(`检测到错误格式IP【${value}】`));
            } else {
              callback();
            }
          },
          trigger: 'blur'
        };
      }
    },
    /**
     * 校验 (1 - 65535) 数字
     * 端口校验
     */
    validatorPort: {
      validator(params) {
        return {
          validator: (rule, value, callback) => {
            const reg = /^[0-9]*$/;
            if (!value) {
              callback(new Error(`请输入${params.name}`));
            } else if (!reg.test(value)) {
              callback(new Error(`端口格式不正确，请输入数字类型`));
            } else if (value < 1 || value > 65535) {
              callback(new Error(`检测到端口范围超出（提示：1 - 65535）`));
            } else {
              callback();
            }
          },
          trigger: 'blur'
        };
      }
    },
  }
  